package cn.stylefeng.guns.modular.hx.storage.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.hx.storage.entity.HxStoreReturnsRegister;
import cn.stylefeng.guns.modular.hx.storage.mapper.HxStoreReturnsRegisterMapper;
import cn.stylefeng.guns.modular.hx.storage.model.params.HxStorageOffShelfParam;
import cn.stylefeng.guns.modular.hx.storage.model.params.HxStoreReturnsRegisterParam;
import cn.stylefeng.guns.modular.hx.storage.model.result.HxStorageOffShelfResult;
import cn.stylefeng.guns.modular.hx.storage.model.result.HxStoreReturnsRegisterResult;
import  cn.stylefeng.guns.modular.hx.storage.service.HxStoreReturnsRegisterService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 门店退货登记 服务实现类
 * </p>
 *
 * @author ZDW
 * @since 2024-09-02
 */
@Service
public class HxStoreReturnsRegisterServiceImpl extends ServiceImpl<HxStoreReturnsRegisterMapper, HxStoreReturnsRegister> implements HxStoreReturnsRegisterService {

    @Override
    public void add(HxStoreReturnsRegisterParam param){
        HxStoreReturnsRegister entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(HxStoreReturnsRegisterParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(HxStoreReturnsRegisterParam param){
        HxStoreReturnsRegister oldEntity = getOldEntity(param);
        HxStoreReturnsRegister newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }
    @Override
    public HxStoreReturnsRegisterResult findBySpec(HxStoreReturnsRegisterParam param){
        return null;
    }

    @Override
    public List<HxStoreReturnsRegisterResult> findListBySpec(HxStoreReturnsRegisterParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(HxStoreReturnsRegisterParam param,String condition,Long operateId){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param,condition, operateId);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(HxStoreReturnsRegisterParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private HxStoreReturnsRegister getOldEntity(HxStoreReturnsRegisterParam param) {
        return this.getById(getKey(param));
    }

    private HxStoreReturnsRegister getEntity(HxStoreReturnsRegisterParam param) {
        HxStoreReturnsRegister entity = new HxStoreReturnsRegister();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }


}
